<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition>
	<f:event listener="#{orderController.fetchOrdersFromUser}"
		type="preRenderComponent"></f:event>
	<p:dataTable id="orderListTable" var="order"
		value="#{userModel.authenticatedUser.orders}" paginatorAlwaysVisible="false"
		paginator="true" rows="15" rowsPerPageTemplate="5,7,10,15,20,30,40,50"
		paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
		<p:column headerText="#{msgs.orderNumber}" sortBy="#{order.number}">
			<h:outputText value="#{order.number}" />
		</p:column>
		<p:column headerText="#{msgs.status}" sortBy="#{order.status.label}">
			<h:outputText value="#{order.status.label}" />
		</p:column>
		<p:column headerText="#{msgs.orderedDate}"
			sortBy="#{order.orderedDate}">
			<h:outputText value="#{order.orderedDate}" />
		</p:column>
		<p:column headerText="#{msgs.requiredDate}"
			sortBy="#{order.requiredDate}">
			<h:outputText value="#{order.requiredDate}" />
		</p:column>
		<p:column headerText="#{msgs.deliveredDate}"
			sortBy="#{order.deliveredDate}">
			<h:outputText value="#{order.deliveredDate}" />
		</p:column>
		<p:column style="width:150px">			
				<p:commandButton icon="view" oncomplete="orderDlg.show()"
					title="#{msgs.viewOrderDetail}" update=":dialogForm">
					<f:setPropertyActionListener value="#{order}"
						target="#{orderController.modelCurrent}" />
				</p:commandButton>
				<p:commandButton icon="cancelOrder" ajax="true"
					disabled="#{!order.canCancel}" title="#{msgs.cancelOrder}"
					oncomplete="orderDeleteDlg.show()" update=":dialogForm">
					<f:setPropertyActionListener value="#{order}"
						target="#{orderController.modelCurrent}" />
				</p:commandButton>
				<p:commandButton icon="edit" ajax="true"
					disabled="#{!order.canEdit}" title="#{msgs.editOrder}"
					actionListener="#{orderController.editCurrent}" update=":dialogForm,:headerForm,:centerForm">
					<f:attribute name="order" value="#{order}"></f:attribute>
				</p:commandButton>
		
		</p:column>
	</p:dataTable>
</ui:composition>
</html>